<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	/**
	 * Exception for the __autoload function.
	 *
	 * It is possible to catch this exception and do a special handling. But within
	 * the __autolaod function, a dummy class with the requested class name was generated
	 * so that you cannot create or load the required class after this exception was thrown.
	 *
	 * These things are done to tamp PHP's leak of real exceptions usage. Otherwise the
	 * script would stop directly after the class not found error with no chance to create
	 * a sufficient output by handling this exception.
	 *
	 * For reporting issues the file, line and trace are adjusted, to remove the influence of
	 * the intermediate __autoload call.
	 */

	class ClassNotFoundException extends TekunaException {


		protected function getAdjustedFile() {

			// get the trace
			$arrTrace = $this -> getTrace();

			// the original file is the previous file if existent
			if (isset($arrTrace[0]['file'])) {
			
				return $arrTrace[0]['file'];
			}
			else {
				
				return parent :: getAdjustedFile();
			}
		}


		protected function getAdjustedLine() {

			// get the trace
			$arrTrace = $this -> getTrace();

			// the original line is the previous line if existent
			if (isset($arrTrace[0]['file'])) {
			
				return $arrTrace[0]['line'];
			}
			else {
				
				return parent :: getAdjustedLine();
			}
		}


		protected function getAdjustedTrace() {

			// get the trace
			$arrTrace = $this -> getTrace();

			// return the trace without the first element if existent
			if (isset($arrTrace[0]['file'])) {
			
				return array_slice($arrTrace, 1);
			}
			else {
				
				return parent :: getAdjustedTrace();
			}
		}
	}
